package com.zp.crm.service.LostService.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zp.crm.dao.LostDao.LostDao;
import com.zp.crm.dto.LostDto.LostDto;
import com.zp.crm.entity.LostEntity.LostEntity;
import com.zp.crm.service.LostService.LostService;
import com.zp.crm.util.targetLog.Log;
@Service("lostService")
public class LostServiceImpl implements LostService {
	@Resource
	public LostDao lDao;
	@Log(name="查询流失信息列表，可根据条件查询 ")
	@Override
	public Map<String, Object> select(String stuts, String username, String name, int page, int size) {
		
		int PageIndex=(page-1)*size;
		
		String html="";
		
		int count=lDao.selectCount(stuts,username,name);
		
		List<LostEntity> list=lDao.select(stuts,username,name,PageIndex,size);
		
		if(username == null && name ==null){
			html=new LostDto().Html(count,list,page,0,stuts);
		}else{
			html=new LostDto().Html(count,list,page,1,stuts);
		}
		
		Map<String, Object> map=new HashMap<>();
		
		map.put("message", html);
		return map;
	}
	@Log(name="查询指定的客户流失信息 ")
	@Override
	public Map<String, Object> selectCode(String code) {
		Map<String, Object> map=new HashMap<>();
		
		if(code != null){
			LostEntity entity=lDao.SelectCode(code);
			
			if(entity!=null){
				map.put("success", true);
				map.put("message", entity);
			}else{
				map.put("success", false);
				map.put("message", "请刷新从试！");
			}
			
		}else{
			map.put("success", false);
			map.put("message", "系统错误！");
		}
		return map;
	}
	@Log(name="修改客户流失信息 ")
	@Override
	public Map<String, Object> edit(String code, String zhcs, String lsyy,String stuts) {
		Map<String, Object> map=new HashMap<>();
		
		int r=lDao.edit(code,zhcs,lsyy,stuts);
		
		if(r>0){
			map.put("success", true);
			map.put("message", "操作成功！");
		}else{
			map.put("success", false);
			map.put("message", "操作失败！");
		}

		return map;
	}

}
